package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppFansClub;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 粉丝团
 */
@Repository
public class AppFansClubDao extends BaseDao<AppFansClub>{

    /**
     * 查询列表
     */
    public List<AppFansClub> fanlituanList() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_fans_club where 1=1  ");
        sbStr.append(" GROUP BY userid ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppFansClub.class,null);
    }

    /**
     * 查询列表
     */
    public List<AppFansClub> roomList(Integer roomid,SplitPageBean splitPageBean) {
        if(roomid==null || roomid<=0){
            return null;
        }
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_fans_club where roomid = ?  GROUP BY userid  ");
        paramList.add(roomid);
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppFansClub.class,splitPageBean);
    }


    /**
     * 详情
     */
    public AppFansClub get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_fans_club where id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppFansClub.class);
    }

    /**
     * 详情
     */
    public AppFansClub getFensiTuan(Integer userid,Integer roomcode) {
        if (userid==null || userid<=0 || StringEx.isNullOrLing(roomcode)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_fans_club where userid = ? and roomcode = ?   ");
        paramList.add(userid);
        paramList.add(roomcode);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppFansClub.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppFansClub haoYou) {
        if (haoYou!=null && haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_fans_club where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 更新用户头像
     * @param userid
     * @param pic 头像地址
     */
    public void updateImg(Integer userid,String pic){
        if(userid==null || userid<=0 || StringEx.isNull(pic) ){
            return ;
        }
        String sql = " UPDATE app_fans_club SET pic = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
     * 更新用户昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateNick(Integer userid,String nick){
        if(userid==null || userid<=0 || StringEx.isNull(nick) ){
            return ;
        }
        String sql = " UPDATE app_fans_club SET nick = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }
}
